package com.zr.share.aop.logger;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName UiController
 * @Description TODO 日志打印接口调用
 * @Author Jiakui_Ma
 * @Date 2019/11/12 13:33
 */
@Component
@Aspect
@Slf4j
public class UiController {

    @Pointcut("execution(public * com.zr.planclass.controller.PlanClassController.*(..))")
    public void pointCut(){
        System.out.println("切面类");
    }

    @Before("pointCut()")
    public void before() throws Exception{
        //获取请求信息的代码

        //统一日志管理
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String method = request.getMethod();
        String url = request.getRequestURI();
        String canshu = request.getQueryString();
        String token = request.getParameter("token");
        log.info("请求的类型"+method);
        log.info("请求的地址"+url);
        log.info("请求的参数"+canshu);
        //鉴权
       /* if (!token.equals("123")){
            throw new Exception();
        }*/

        log.info("请求controller之前走的方法！");
    }
}
